package com.prs.crm.action.oa;

import java.util.Collection;
import java.util.Date;
import java.util.List;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Result;
import org.courser.struts.BaseAction;
import org.courser.ui.PaginationSupport;
import org.courser.ui.TreeNode;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;


import com.prs.crm.context.FileUtil;
import com.prs.crm.domain.doc.DocumentTaskType;
import com.prs.crm.domain.hr.Dept;
import com.prs.crm.domain.oa.Vehicle;
import com.prs.crm.domain.oa.VehicleInsurance;
import com.prs.crm.domain.oa.VehicleInsuranceType;
import com.prs.crm.service.oa.VehicleInsuranceService;
import com.prs.crm.service.oa.VehicleInsuranceTypeService;
import com.prs.crm.service.oa.VehicleService;

public class VehicleInsuranceAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private PaginationSupport pagination;
	private VehicleInsurance vehicleInsurance;
	private VehicleInsuranceService vehicleInsuranceService;
	private List<Vehicle> ins;
	private VehicleService vehicleService;
	private VehicleInsuranceTypeService vehicleInsuranceTypeService;
	private TreeNode root;
	private Integer[] vehicleInsuranceIds;
	
	@Action("editVehicleInsurance")
	public String editVehicleInsurance() {
		this.ins=this.vehicleService.getVehicleAll();
		return SUCCESS;
	}
	@Action("viewVehicleInsurance")
	public String viewVehicleInsurance() {
		
		return SUCCESS;
	}
	@Action("listVehicleInsurance")
	public String listVehicleInsurance() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				VehicleInsurance.class);
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.vehicleInsuranceService.listByPage(criteria,
				pagination));
		return SUCCESS;
	}
	@Action("listVehicleInsuranceRemind")
	public String listVehicleInsuranceRemind() {
		DetachedCriteria criteria = this.getPaginationHelper().createQuery(
				VehicleInsurance.class);
		criteria.add(Restrictions.lt("endTime", new Date()));
		pagination = this.getPaginationHelper().prepare(pagination);
		this.setPagination(this.vehicleInsuranceService.listByPage(criteria,
				pagination));
		return SUCCESS;
	}
	@Action(value = "saveVehicleInsurance", results = {
			@Result(name = "success", type = "redirect", location = "listVehicleInsurance"),
			@Result(name = "error", type = "chain", location = "editVehicleInsurance") })
	public String saveVehicleInsurance(){
		this.vehicleInsuranceService.save(vehicleInsurance);
		return SUCCESS;
	}
	@Action(value = "removeVehicleInsurance", results = {
			@Result(name = "success", type = "redirect", location = "listVehicleInsurance"),
			@Result(name = "error", type = "chain", location = "listVehicleInsurance") })
	public String removeVehicleInsurance(){
		if(vehicleInsuranceIds==null){
			this.addActionError("请选择操作行！");
			return ERROR;
		}
		this.getVehicleInsuranceService().batchRemove(vehicleInsuranceIds);
		return SUCCESS;
	}	
	public PaginationSupport getPagination() {
		return pagination;
	}
	public void setPagination(PaginationSupport pagination) {
		this.pagination = pagination;
	}
	public VehicleInsurance getVehicleInsurance() {
		return vehicleInsurance;
	}
	public void setVehicleInsurance(VehicleInsurance vehicleInsurance) {
		this.vehicleInsurance = vehicleInsurance;
	}
	public VehicleInsuranceService getVehicleInsuranceService() {
		return vehicleInsuranceService;
	}
	public void setVehicleInsuranceService(
			VehicleInsuranceService vehicleInsuranceService) {
		this.vehicleInsuranceService = vehicleInsuranceService;
	}
	
	public List<Vehicle> getIns() {
		return ins;
	}
	public void setIns(List<Vehicle> ins) {
		this.ins = ins;
	}
	public VehicleService getVehicleService() {
		return vehicleService;
	}
	public void setVehicleService(VehicleService vehicleService) {
		this.vehicleService = vehicleService;
	}
	public VehicleInsuranceTypeService getVehicleInsuranceTypeService() {
		return vehicleInsuranceTypeService;
	}
	public void setVehicleInsuranceTypeService(
			VehicleInsuranceTypeService vehicleInsuranceTypeService) {
		this.vehicleInsuranceTypeService = vehicleInsuranceTypeService;
	}
	public TreeNode getRoot() {
		return root;
	}
	public void setRoot(TreeNode root) {
		this.root = root;
	}
	public Integer[] getVehicleInsuranceIds() {
		return vehicleInsuranceIds;
	}
	public void setVehicleInsuranceIds(Integer[] vehicleInsuranceIds) {
		this.vehicleInsuranceIds = vehicleInsuranceIds;
	}
}
